package org.benjamin.lending.domain.entity;

import com.fasterxml.jackson.annotation.JsonFormat;

import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;

import javax.persistence.*;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@Entity
@Table(name = "tab_borrow_info")
public class BorrowInfo implements Serializable{

	private static final long serialVersionUID = 1L;

	public BorrowInfo(){}

	public BorrowInfo(Integer id){
		this.id = id;
	}


	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	
	@Column(name = "no",nullable = false,unique = true)
	private String no;

	@ManyToOne
	@JoinColumn(name = "business_id")
	private BusinessInfo businessInfo;

	@ManyToOne
	@JoinColumn(name = "user_id")
	private MemberInfo memberInfo;
	
	@Column(name = "name",nullable = false)
	private String name;
	
	@Column(name = "period",nullable = false)
	private Integer period;
	
	@ManyToOne
	@JoinColumn(name = "product")
	private BorrowProduct borrowProduct;
	
	/**
	 * 投资利息
	 */
	@Column(name = "invest_rate",nullable = false)
	private BigDecimal investRate;
	
	@Column(name = "invest_reward")
	private BigDecimal investReward = BigDecimal.ZERO;
	
	@Column(name = "contnue_reward")
	private BigDecimal continueReward = BigDecimal.ZERO;
	
	/**
	 * 一共要募集金额
	 */
	@Column(name = "total_money",nullable = false)
	private BigDecimal totalMoney;
	
	/**
	 * 累计投资金额
	 */
	@Column(name = "invest_money",nullable = false)
	private BigDecimal investMoney = BigDecimal.ZERO;
	
	/**
	 * 最小投资金额
	 */
	@Column(name = "min_invest")
	private BigDecimal minInvest = BigDecimal.ZERO;
	
	/**
	 * 借款管理费
	 */
	@Column(name = "management_expense")
	private BigDecimal managementExpense;

	@Enumerated(EnumType.STRING)
	@Column(name = "status",nullable = false)
	private BorrowStatus status;

	@Enumerated(EnumType.STRING)
	@Column(name = "payment_method",nullable = false)
	private PaymentMethod paymentMethod;
	
	@Column(name = "create_time",nullable = false)
	private Timestamp createTime;
	
	@Column(name = "publish_time")
	private Timestamp publishTime;
	
	@Column(name = "loan_time")
	private Timestamp loanTime;
	
	@Column(name = "finish_time")
	private Timestamp finishTime;
	
	@Lob
	@Column(name = "project_description")
	private String projectDescription;

	/**
	 * 获得借款标的ID唯一键
	 * @return
	 */
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * 候选键用于与Web传输
	 * @return
	 */
	public String getNo() {
		return no;
	}

	public void setNo(String no) {
		this.no = no;
	}

	public BusinessInfo getBusinessInfo() {
		return businessInfo;
	}

	public void setBusinessInfo(BusinessInfo businessInfo) {
		this.businessInfo = businessInfo;
	}

	/**
	 * 借款人信息
	 * @return
	 */
	public MemberInfo getMemberInfo() {
		return memberInfo;
	}

	public void setMemberInfo(MemberInfo memberInfo) {
		this.memberInfo = memberInfo;
	}

	/**
	 * 借款标名称
	 * @return
	 */
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	/**
	 * 借款标期限
	 * @return
	 */
	public Integer getPeriod() {
		return period;
	}

	public void setPeriod(Integer period) {
		this.period = period;
	}

	/**
	 * 借款标的年化收益率
	 * @return
	 */
	@NotNull
	@Min(value = 3)
	public BigDecimal getInvestRate() {
		return investRate;
	}

	public void setInvestRate(BigDecimal investRate) {
		this.investRate = investRate;
	}

	/**
	 * 投资奖励比例
	 * @return
	 */
	public BigDecimal getInvestReward() {
		return investReward;
	}

	public void setInvestReward(BigDecimal investReward) {
		this.investReward = investReward;
	}

	/**
	 * 续投奖励比例
	 * @return
	 */
	public BigDecimal getContinueReward() {
		return continueReward;
	}

	public void setContinueReward(BigDecimal continueReward) {
		this.continueReward = continueReward;
	}

	/**
	 * 借款标要募集总金额
	 * @return
	 */
	@JsonFormat(pattern = "##,##.##")
	public BigDecimal getTotalMoney() {
		return totalMoney;
	}

	public void setTotalMoney(BigDecimal totalMoney) {
		this.totalMoney = totalMoney;
	}

	/**
	 * 借款标已经投资金额
	 * @return
	 */
	public BigDecimal getInvestMoney() {
		return investMoney;
	}

	public void setInvestMoney(BigDecimal investMoney) {
		this.investMoney = investMoney;
	}

	public BigDecimal getMinInvest() {
		return minInvest;
	}

	public void setMinInvest(BigDecimal minInvest) {
		this.minInvest = minInvest;
	}

	/**
	 * 借款标状态
	 * @return
	 */
	public BorrowStatus getStatus() {
		return status;
	}

	public void setStatus(BorrowStatus status) {
		this.status = status;
	}

	/**
	 * 还款方式
	 * @return
	 */
	public PaymentMethod getPaymentMethod() {
		return paymentMethod;
	}

	public void setPaymentMethod(PaymentMethod paymentMethod) {
		this.paymentMethod = paymentMethod;
	}

	/**
	 * 创建时间
	 * @return
	 */
	@JsonFormat(locale = "zh",timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
	public Timestamp getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Timestamp createTime) {
		this.createTime = createTime;
	}

	/**
	 * 发布时间
	 * @return
	 */
	public Timestamp getPublishTime() {
		return publishTime;
	}

	public void setPublishTime(Timestamp publishTime) {
		this.publishTime = publishTime;
	}

	/**
	 * 放宽时间
	 * @return
	 */
	public Timestamp getLoanTime() {
		return loanTime;
	}

	public void setLoanTime(Timestamp loanTime) {
		this.loanTime = loanTime;
	}

	/**
	 * 完成时间
	 * @return
	 */
	public Timestamp getFinishTime() {
		return finishTime;
	}

	public void setFinishTime(Timestamp finishTime) {
		this.finishTime = finishTime;
	}

	public String getProjectDescription() {
		return projectDescription;
	}

	public void setProjectDescription(String projectDescription) {
		this.projectDescription = projectDescription;
	}

	public BorrowProduct getBorrowProduct() {
		return borrowProduct;
	}

	public void setBorrowProduct(BorrowProduct borrowProduct) {
		this.borrowProduct = borrowProduct;
	}

	public BigDecimal getManagementExpense() {
		return managementExpense;
	}

	public void setManagementExpense(BigDecimal managementExpense) {
		this.managementExpense = managementExpense;
	}
	
	
	
}
